package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingLevelServiceImpl
 * @Author Wen Jie
 * @Date 2024-09-09
 */
@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;
    @Override
    public List<NursingLevelVo> listAll() {
        List<NursingLevel> nursingLevels = nursingLevelMapper.listAll();
        List<NursingLevelVo> nursingLevelVos = BeanUtil.copyToList(nursingLevels, NursingLevelVo.class);
        return nursingLevelVos;
    }

    @Override
    public PageResponse<NursingLevelVo> listByPage(String name, String status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> nursingLevels = nursingLevelMapper.listByPage(name,status);
        return PageResponse.of(nursingLevels, NursingLevelVo.class);
    }

    @Override
    public void addNursingLevel(NursingLevelVo nursingLevelVo) {
        nursingLevelVo.setStatus(1);
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelVo, NursingLevel.class);
        nursingLevelMapper.addNursingLevel(nursingLevel);
    }

    @Override
    public NursingLevelVo getById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.getById(id);
        NursingLevelVo nursingLevelVo = BeanUtil.toBean(nursingLevel, NursingLevelVo.class);
        return nursingLevelVo;
    }

    @Override
    public void updateNursingLevel(NursingLevelVo nursingLevelVo) {
        nursingLevelVo.setUpdateBy(1L);
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelVo, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void updateStatusById(Long id, Integer status) {
        nursingLevelMapper.updateStatusById(id,status);
    }
}
